package code.framework.android.activity;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import code.framework.android.core.ApplicationContextHelper;
import code.framework.android.view.ApplicationViewManager;

import com.google.inject.Inject;

public abstract class ListActivityBase extends ListActivity implements
		InjectorProvider {

	@Inject
	private ActivitySupport activitySupport;

	@Inject
	private ApplicationViewManager applicationViewManager;

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// logger.debug("onCreate()");
		super.onCreate(savedInstanceState);

		// activitySupport.inject(this.getInjector(), this);
		this.getInjector().injectMembers(this);
		activitySupport.configure(this);
		final String simpleClassName = super.getClass().getSimpleName().replace("Activity", "");
		logger.trace("simpleClassName = {}", simpleClassName);
		final String layoutId = ApplicationContextHelper.convertClassNameToDbName(simpleClassName);
		logger.trace("layoutId = {}", layoutId);
		applicationViewManager.setContentView(this, layoutId);
		activitySupport.supportSetup(this);
	}

	@Override
	protected void onResume() {
		// logger.debug("onResume()");
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		// logger.debug("onDestroy()");
		super.onDestroy();
	}

	protected void load() {
		logger.debug("load()");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		logger.debug("onCreateOptionsMenu()");

		activitySupport.supportConfigureMenu(menu, this);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		logger.debug("onOptionsItemSelected()");

		activitySupport.supportConfigureMenuSelected(item, this);

		return true;
	}

}
